package com.murphy.mq.activemq.listener;

import org.apache.activemq.Message;
import org.apache.activemq.command.ActiveMQTextMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.listener.SessionAwareMessageListener;

import javax.jms.JMSException;
import javax.jms.Session;
import javax.jms.TextMessage;
import java.io.IOException;

/**
 * Created by Ares on 2017/11/15.
 */
public class TransactionBizMessageListener implements SessionAwareMessageListener<Message> {

//    @Autowiredired
//    StuffServiceFacade stuffServiceFacade;


    @Override
    public void onMessage(Message message, Session session) throws JMSException {
        //获取消息内容
        ActiveMQTextMessage msg = (ActiveMQTextMessage) message;
        System.out.println(msg);
        String text = null;
        text = msg.getText();
        System.out.println(text);
        //json转换为对象
        try {
//            TStuff tstuff = JacksonJsonUntil.jsonToPojo(text, TStuff.class);
//            TStuff stuff = new TStuff();
//            stuff.setSex(tstuff.getSex());
//            stuff.setName("德玛西亚");
//            stuff.setClassid(tstuff.getClassid());
//            stuff.setAddress(tstuff.getAddress());
            int i = 0;//stuffServiceFacade.insertStuff(stuff);
            if (i>0){
                System.out.println("添加职员成功");
            }
            else {
                System.out.println("添加职员失败");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
